package cn.dy.sbo.util;

import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import java.util.Locale;

import com.opensymphony.xwork2.ActionContext;

public class CommonUtils
{
    public static String convertParam(String str)
    {
        return "%" + str + "%";
    }

    /**
     * MD5加密
     * 
     * @param data
     * @return
     * @throws Exception
     */
    public static String encryptMD5(String data) throws Exception
    {

        Md5PasswordEncoder encode = new Md5PasswordEncoder();
        return encode.encodePassword(data, null);
    }

    public static Locale  getLocal(){
        Object obj  = null;
		if(ActionContext.getContext() != null)
			obj = Struts2Utils.getSession().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
		return (Locale) obj;
    }

    public static void main(String[] args) throws Exception
    {
        System.out.println(CommonUtils.encryptMD5("1234"));
    }

    public static String getCurUserName()
    {
        return SpringSecurityUtils.getCurrentUserName();
    }
}
